package com.zwy.alhorthms;

/**
 * 冒泡排序
 * @author 天火
 * @className BubbleSort
 */
public class BubbleSort {

    private  static ArrayData data =  new ArrayData();


    public static void main(String[] args) {

        int[] arr = data.getData();
        bubbleSort(data.getData());
        print(data.getData());

    }
    static void  bubbleSort(int[] arr){
        int swap = 0;
        for(int i = arr.length;i>0;i--){
            for(int j = 0; j<i-1;j++){
                if(arr[j]>arr[j+1]){
                    swap(arr,j);
                    System.out.println("交换的位置：" + j);
                    if(j==0){
                        swap = j;
                    }else {
                        swap = j + 1;
                    }

                }
            }
            System.out.println(i);
            i = swap +1;;
        }
    }
    static void swap(int[] arr,int j){
        int temp = arr[j];
        arr[j] = arr[j+1];
        arr[j+1] = temp;
    }

    static void print(int[] arr){
        for(int value : arr){
            System.out.print(value + "    ");
        }
    }



}
